import * as echarts from '../ec-canvas/echarts';
// 饼图
let chartPie;
function getPieOption() {
  let option = {
    title: {
      text: '报修类型占比',
      left: 'center'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      left: 'center',
      top: "40"
    },
    series: [{
      name: '报修类型占比',
      type: 'pie',
      radius: '50%',
      center: ['50%', '60%'],
      data: [],
      emphasis: {
        itemStyle: {
          shadowBlur: 10,
          shadowOffsetX: 0,
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      }
    }]
  };
  return option
}
function initChartPie(canvas, width, height, dpr) {
  chartPie = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr // new
  });
  canvas.setChart(chartPie);
  let option = getPieOption();
  chartPie.setOption(option);
  return chartPie;
}
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    oData:{
      type:Array,
      value:[],
      observer: function (newVal, oldVal, changedPath) {
        if (newVal.length>0) {
          setTimeout(()=>{
            chartPie.setOption({
              series: [{
                data: newVal
              }]
            });
          },500)
          
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    ec: {
      onInit: initChartPie, // 3、将数据放入到里面
    }
  },
  attached(){
  },
  /**
   * 组件的方法列表
   */
  methods: {

  }
})
